package com.dylan.历史.guava;

import com.google.common.collect.Sets;
import org.junit.Test;

import java.util.Set;

/**
 * @author : ankang
 * @date : 2019/10/21 18:40
 * @Description :
 */
public class 集合交并补 {

    private Set<Integer> set1 = Sets.newHashSet(1, 2, 3);

    private Set<Integer> set2 = Sets.newHashSet(2, 3, 4, 5);

    @Test
    public void testUnion() {
        Sets.SetView<Integer> union = Sets.union(set1, set2);
        System.out.println(set1);
        System.out.println(set2);
        System.out.println(union);
    }

    @Test
    public void testIntersection() {
        Sets.SetView<Integer> intersection = Sets.intersection(set1, set2);
        System.out.println(set1);
        System.out.println(set2);
        System.out.println(intersection);
    }

    @Test
    public void testDifferenceLeft() {
        Sets.SetView<Integer> difference = Sets.difference(set1, set2);
        System.out.println(set1);
        System.out.println(set2);
        System.out.println(difference);
    }

    @Test
    public void testDifferenceRight() {
        Sets.SetView<Integer> difference = Sets.difference(set2, set1);
        System.out.println(set1);
        System.out.println(set2);
        System.out.println(difference);
    }

    @Test
    public void testSymmetricDifference() {
        Sets.SetView<Integer> symmetricDifference = Sets.symmetricDifference(set2, set1);
        System.out.println(set1);
        System.out.println(set2);
        System.out.println(symmetricDifference);
    }
}
